package com.xyck.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xyck.manage.domain.Records;
import com.xyck.manage.domain.vo.ArticleVo;
import com.xyck.manage.domain.dto.ArticleDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xyck.common.annotation.Log;
import com.xyck.common.core.controller.BaseController;
import com.xyck.common.core.domain.AjaxResult;
import com.xyck.common.enums.BusinessType;
import com.xyck.manage.domain.Article;
import com.xyck.manage.service.IArticleService;
import com.xyck.common.utils.poi.ExcelUtil;
import com.xyck.common.core.page.TableDataInfo;

/**
 * 物品管理Controller
 * 
 * @author 星野漫游
 * @date 2024-07-07
 */
@RestController
@RequestMapping("/manage/article")
public class ArticleController extends BaseController
{
    @Autowired
    private IArticleService articleService;

    /**
     * 查询物品管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleDto articleDto)
    {
        startPage();
        List<ArticleVo> list = articleService.selectArticleVoList(articleDto);
        return getDataTable(list);
    }

    /**
     * 导出物品管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:article:export')")
    @Log(title = "物品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Article article)
    {
        List<Article> list = articleService.selectArticleList(article);
        ExcelUtil<Article> util = new ExcelUtil<Article>(Article.class);
        util.exportExcel(response, list, "物品管理数据");
    }

    /**
     * 获取物品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(articleService.selectArticleById(id));
    }

    /**
     * 新增物品管理
     */
    @PreAuthorize("@ss.hasPermi('manage:article:add')")
    @Log(title = "物品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleDto articleDto)
    {
        return toAjax(articleService.insertArticle(articleDto));
    }

    /**
     * 修改物品管理
     */
    @PreAuthorize("@ss.hasPermi('manage:article:edit')")
    @Log(title = "物品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleDto articleDto)
    {
        return toAjax(articleService.updateArticle(articleDto));
    }

    /**
     * 删除物品管理
     */
    @PreAuthorize("@ss.hasPermi('manage:article:remove')")
    @Log(title = "物品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(articleService.deleteArticleByIds(ids));
    }


    /**
     * 出库物品管理
     */
    @PreAuthorize("@ss.hasPermi('manage:article:outBound')")
    @Log(title = "物品管理", businessType = BusinessType.INSERT)
    @PostMapping("outBound")
    public AjaxResult outBound(@RequestBody Records records )
    {
        return toAjax(articleService.outBound(records));
    }

}
